// ----------------------------------------------------------------------------
// Created:			Sept 11, 2010
//
// Description:		This set of functions will provide access to text based config files.
//					These files will have to follow a strict format.
// ----------------------------------------------------------------------------

#ifndef CDATAFILE_H
#define CDATAFILE_H

// Entry Types
#define			ENTRY_FLOAT		0x0001
#define			ENTRY_INT		0x0002
#define			ENTRY_STRING	0x0003

// ------------------------------------------------------------------
// The following are a couple structures used to load data files from
// Disk.  The "Entry" structure will hold a basic unit of data.
// It will also contain a pointer to the next entry in the collection.
//
// The "Collection" struct will contain a set of entries.  This will
// allow grouping of entries to make it easier to write files and
// keep them organized.  The entire file will be contained in one "root"
// collection object.
// ------------------------------------------------------------------

// Property: a single line in the text file
typedef struct tagDataEntry
{
	char			*pName;				// Name of Property
	char			*pValue;			// Value of property
	int				type;				// Type of data (string, int, or float)
	tagDataEntry	*pNext;				// Pointer to the next property
	tagDataEntry	*pPrev;				// Pointer to the previous property
}DataEntry;


typedef struct tagDataCollection
{
	char			*sName;				// Name of this object
	tagDataCollection	*pParentCollection;	// Parent collection, NULL if root
	int				numOfEntries;		// How many entries in this object
	int				numOfCollections;	// Number of collections within this object
	DataEntry			*pHeadEntry;		// Pointer to entries
	tagDataCollection	*pHeadCollection;	// Pointer to child collections
	tagDataCollection	*pNext;				// Pointer to sibling collections
	tagDataCollection	*pPrev;				// Pointer to the previous collection in list.
}DataCollection;

class CDataFile
{
public:
	CDataFile();
	~CDataFile();
	
	// Load a data file and return the resulting DataObject to the caller
	// Also funtion to unload a dataobject.  This will free all memory allocated
	// for the object.
	int		LoadDataFile(char *filename, int flags);
	int		UnloadDataFile(void);

	// debugging methods
	// Print out a tree like list of the given object.
	int PrintCollection(void);

	// Extract a child object out of a larger object
	//DataObject * GetChildOb(DataObject *pRootObject, char *pszChildObject);

	// Methods to extract the data loaded from a file.
	int		GetInt(char *Collection, char *Entry);
	float	GetFloat(char *Collection, char *Entry);
	char	*GetString(char *Collection, char *Entry);

private:
	// Initialization methods.  Will allocate memory and clear members to null values.
	int				Initialize(void);	
	void			ClearData(DataCollection *data);
	
	DataCollection	*pRoot;		// This is the object that is used for loading files.

}; // class CDataFile


#endif

